﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 12/04/2009
// Time: 12:12
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Drawing;
using System.Windows.Forms;

namespace csharp.rad.finan.entries
{
	/// <summary>
	/// Description of frmRegisterBank.
	/// </summary>
	public partial class frmRegisterBank : common.simpleRegisterTemplate
	{
		Bank bank = new Bank();
		Banks list = new Banks();
		
		public frmRegisterBank()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
		}
		
		#region overrided methods
			protected override void newEvent()
			{
				bank.clear();
			}
            
			/// <summary>
			/// Set data from edits to class
			/// </summary>
			protected override void setClass()
			{
				bank.name = txtName.Text;
			}
			
			/// <summary>
			/// Set data from class to edits
			/// </summary>
			protected override void setEdits()
			{
				bank.id = dgvMain.CurrentRow.Cells["id"].Value.ToString();
				
				if (bank.get())
				{
					txtName.Text = bank.name;
				}
			}
			
			/// <summary>
			/// Fill the DataGridView
			/// </summary>
			protected override void fillDataGridView()
			{
				int tam;
				list.fillList();
				
				tam = list.count();
				dgvMain.Rows.Clear();
				for (int i=0; i < tam; i++)
				{
					dgvMain.Rows.Add(new String[] {list.get(i).id, list.get(i).name});
				}				
			}
			
			
		   /// <summary>
		   /// Save the register in the database.
		   /// </summary>
		   /// <returns>bool - true if the register was saved sucessful, false case not.</returns>	
		   protected override bool save()
		   {
		   	return bank.save();
		   }
		   
		   /// <summary>
		   /// Update the register in the database
		   /// </summary>
		   /// <returns>bool - true if the register was updated sucessful, false case not.</returns>
		   protected override bool update()
		   {   
		   	return bank.update();
		   }
		   
		   /// <summary>
		   /// Delete the register in the database.
		   /// </summary>
		   /// <returns>bool - true if the register was deleted sucessful, false case not.</returns>
		   protected override bool delete()
		   {
            bank.id = dgvMain.CurrentRow.Cells["id"].Value.ToString();
		   	return bank.delete();
		   }
		   
		   /// <summary>
		   /// Method call in initialization
		   /// </summary>
		   protected override void init()
		   {

		   }
		#endregion		
	}
}
